package com.example.mbl.controller;

import com.example.mbl.dto.IndexDto;
import com.example.mbl.entity.IndexMotto;
import com.example.mbl.entity.IndexPic;
import com.example.mbl.interceptor.AppToken;
import com.example.mbl.result.PageResult;
import com.example.mbl.result.WebRestResult;
import com.example.mbl.result.business.IndexResult;
import com.example.mbl.service.ArticleService;
import com.example.mbl.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("Index")
public class IndexController {
    @Autowired
    private IndexService indexService;

    @AppToken
    @PostMapping("addIndexPic")
    public WebRestResult addIndexPic(@RequestBody IndexDto indexDto){
        WebRestResult result = indexService.addIndexPic(indexDto);
        return result;
    }

    @AppToken
    @PostMapping("addIndexMotto")
    public WebRestResult addIndexMotto(@RequestBody IndexDto indexDto){
        WebRestResult result = indexService.addIndexMotto(indexDto);
        return result;
    }

    @AppToken
    @PostMapping("deleteIndexPic")
    public WebRestResult deleteIndexPic(@RequestBody IndexDto indexDto){
        WebRestResult result = indexService.deleteIndexPic(indexDto);
        return result;
    }

    @AppToken
    @PostMapping("deleteIndexMotto")
    public WebRestResult deleteIndexMotto(@RequestBody IndexDto indexDto){
        WebRestResult result = indexService.deleteIndexMotto(indexDto);
        return result;
    }

    @AppToken
    @PostMapping("updateIndexPic")
    public WebRestResult updatePic(@RequestBody IndexDto indexDto){
        WebRestResult result = indexService.updateIndexPic(indexDto);
        return result;
    }

    @AppToken
    @PostMapping("updateIndexMotto")
    public WebRestResult updateMotto(@RequestBody IndexDto indexDto){
        WebRestResult result = indexService.updateIndexMotto(indexDto);
        return result;
    }

    @GetMapping("getIndex")
    @CrossOrigin
    public IndexResult getIndex(){
        IndexResult result = indexService.getIndex();
        return result;
    }

    @AppToken
    @PostMapping("updateIntroduction")
    public WebRestResult updateIntroduction(@RequestBody IndexDto indexDto){
        WebRestResult result = indexService.updateIntroduction(indexDto.getIntroduction());
        return result;
    }

    @GetMapping("getIntroduction")
    public WebRestResult getIntroduction(){
        WebRestResult result = indexService.getIntroduction();
        return result;
    }

    @GetMapping("getIndexPicList")
    public PageResult<IndexPic> getIndexPicList(){
        PageResult<IndexPic> result = indexService.getIndexPicList();
        return result;
    }

    @GetMapping("getIndexMottoList")
    public PageResult<IndexMotto> getIndexMotto(){
        PageResult<IndexMotto> result = indexService.getIndexMottoList();
        return result;
    }

    @PostMapping("updateEmployInfo")
    public WebRestResult updateEmployInfo(@RequestBody IndexDto indexDto){
        WebRestResult result = indexService.updateEmployInfo(indexDto.getEmployinfo());
        return result;
    }

    @GetMapping("getEmployInfo")
    public WebRestResult getEmployInfo(){
        WebRestResult result = indexService.getEmployInfo();
        return result;
    }
}
